package com.taotao.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.taotao.common.pojo.EUDataGridResult;
import com.taotao.mapper.ItemMapper;
import com.taotao.pojo.Item;
import com.taotao.service.ItemService;

@Service
public class ItemServiceImpl implements ItemService{
	private static Logger logger = LoggerFactory.getLogger(ItemServiceImpl.class);
	
	@Autowired
	private ItemMapper itemMapper;

	@Override
	public Item selectByPrimaryKey(Long id) {
		Item item = null;
		try{
			item = itemMapper.selectByPrimaryKey(id);
		}catch(Exception e){
			logger.error("获取商品详情时报错:" + e.getMessage());
			e.printStackTrace();
		}
		return item;
	}

	@Override
	public EUDataGridResult getItemList(Integer page, Integer rows) {
		//创建一个返回值对象
		EUDataGridResult result = new EUDataGridResult();
		
		try{
			//查询商品列表
			//TbItemExample example = new TbItemExample();
			//分页处理
			PageHelper.startPage(page, rows);
			//List<Item> list = itemMapper.selectByExample(example);
			Map<String,Object> params = new HashMap<String,Object>();
			params.put("orderByClause", "id");
			List<Item> list = itemMapper.getItemList(params);
			result.setRows(list);
			//取记录总条数
			PageInfo<Item> pageInfo = new PageInfo<Item>(list);
			result.setTotal(pageInfo.getTotal());
		}catch(Exception e){
			logger.error("获取商品详情时报错:" + e.getMessage());
			e.printStackTrace();
		}
		return result;
	}

	@Override
	public int deleteByPrimaryKey(Long id) {
		return itemMapper.deleteByPrimaryKey(id);
	}

	@Override
	public int insert(Item record) {
		return itemMapper.insert(record);
	}

	@Override
	public int insertSelective(Item record) {
		return itemMapper.insertSelective(record);
	}

	@Override
	public int updateByPrimaryKeySelective(Item record) {
		return itemMapper.updateByPrimaryKeySelective(record);
	}

	@Override
	public int updateByPrimaryKey(Item record) {
		return itemMapper.updateByPrimaryKey(record);
	}
}
